<?php


namespace app\api\controller;
use app\facade\Basic;
use think\Request;
use app\api\service\Register as ServiceRegister;

class Register extends BaseController
{
    /**
     *  管理员登录
     */
    public function register(Request $request)
    {
        $param['ip'] = $request->ip();
        $param['role'] = $request->param('role','user');
        $param['cusname'] = $request->param('cusname','');
        $param['email'] = $request->param('email');
        $param['password'] = $request->param('password');
        $param['repeat_password'] = $request->param('repeat_password');

        /* 选填字段 */
        $param['phone_code'] = $request->param('phone_code');
        $param['phone'] = $request->param('phone');
        $param['qq'] = $request->param('qq');
        $param['wechat'] = $request->param('wechat');
        $param['whatsapp'] = $request->param('whatsapp');
        $param['dingtalk'] = $request->param('dingtalk');
        $param['nickname'] = $request->param('nickname');
        $param['country'] = $request->param('country');
        $param['address'] = $request->param('address');
        $param['is_advance'] = $request->param('is_advance');

        /* 邮箱验证码 */
        $param['code'] = $request->param('mail_code');

        /* 验证 */
        $this->validateData($param,'Register.register');

        /* 登录操作 */
        $ServiceRegister = new ServiceRegister();
        $result = $ServiceRegister->register($param);
        return Basic::json($result);
    }


    /**
     *  获取邮箱验证码
     */
    public function getEmailCode(Request $request)
    {
        $param['email'] = $request->param('email');

        /* 验证 */
        $this->validateData($param,'Retrieve.getEmailCode');


        /* 登录操作 */
        $ServiceRegister = new ServiceRegister();
        $result = $ServiceRegister->getEmailCode($param);
        return Basic::json($result);
    }

}
